import temp  from './protolib'
import { Logger } from '../../utils/Logger';

declare var proto;

/** 协议拓展支持 */
export class ProtoUtils {

    public static init(){
        Logger.log("ProtoUtils init==temp=", temp);
        Logger.log("ProtoUtils init==proto=", proto);
    }

    /** 构造协议 */
    public static Create(name: string): any {
        if (!proto[name]) {
            return null;
        }
        return new proto[name]();
    }

    public static CreateQianTao2(name1:string, name2:string){
        return new proto[name1][name2]();
    }

    /** 反序列化 */
    public static DeserializeBinary(name: string, data: any): any {
        if (!proto[name]) { return null; }
        return proto[name].deserializeBinary(data);
    }

    /** 获取协议对象名字 */
    public static GetProtoName(v: any): string {
        // Logger.log("GetProtoName=", v.constructor.displayName.substring(6));
        return v.constructor.displayName.substring(6);
    }

}
